import sys
import os

class FileInfo(Episode):
  path = None

def usage():
  print "Usage message"

def printstr(string):
  if string.endswith(".avi"):
    return string 
  else:
    return None


def process_dir(target_dir, file_processor):
  subdirs = []
  results = []

  try:
    file_names = os.listdir(target_dir)
  except OSError:
    return []

  for file_name in file_names: 
    file_path = os.path.join(target_dir, file_name)
    if os.path.isdir(file_path):
      subdirs.append(file_path)
    else:
      product = file_processor(file_path)
      if product:
        results.append((file_path, product))
  for subdir in subdirs:
    results.extend(process_dir(subdir, file_processor))
  return results

if __name__ == "__main__":

  # Locate our target directory
  try:
    target_dir =  sys.argv[1]
  except IndexError:
    usage()
    sys.exit()
  
  if not os.path.isdir(target_dir):
    print target_dir, "is not a valid directory" 
  else:
    results = process_dir(target_dir, printstr)

  print results


